<!DOCTYPE html>
<html lang=zh>
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000">
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top">
  
  
  <title>spring-boot部署到CentOS服务器、安装Redis、配置Nginx、MySQL | 山岚 - 90码农历险记</title>
  <meta name="description" content="部署到服务器 使用idea的Maven工具，package命令，即可对项目进行打包。也可以手动输入maven命令打包mvn clear package  打包完成以后，是一个jar文件，会存放在你项目的target目录下。我通过WinSCP软件上传到我的阿里云服务里。  项目需要用到Redis，所以我还把Redis压缩包上传到了服务器内，参考了该教程进行安装。Centos7下安装redis - 醉">
<meta name="keywords" content="nginx">
<meta property="og:type" content="article">
<meta property="og:title" content="spring-boot部署到CentOS服务器、安装Redis、配置Nginx、MySQL">
<meta property="og:url" content="https://blog.gobyte.cn/post/c621cb41.html">
<meta property="og:site_name" content="山岚博客">
<meta property="og:description" content="部署到服务器 使用idea的Maven工具，package命令，即可对项目进行打包。也可以手动输入maven命令打包mvn clear package  打包完成以后，是一个jar文件，会存放在你项目的target目录下。我通过WinSCP软件上传到我的阿里云服务里。  项目需要用到Redis，所以我还把Redis压缩包上传到了服务器内，参考了该教程进行安装。Centos7下安装redis - 醉">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2019-12-10T08:14:59.819Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="spring-boot部署到CentOS服务器、安装Redis、配置Nginx、MySQL">
<meta name="twitter:description" content="部署到服务器 使用idea的Maven工具，package命令，即可对项目进行打包。也可以手动输入maven命令打包mvn clear package  打包完成以后，是一个jar文件，会存放在你项目的target目录下。我通过WinSCP软件上传到我的阿里云服务里。  项目需要用到Redis，所以我还把Redis压缩包上传到了服务器内，参考了该教程进行安装。Centos7下安装redis - 醉">
  <!-- Canonical links -->
  <link rel="canonical" href="https://blog.gobyte.cn/post/c621cb41.html">
  
    <link rel="alternate" href="/atom.xml" title="山岚博客" type="application/atom+xml">
  
  
    <link rel="icon" href="/shan-2.png" type="image/x-icon">
  
  <link rel="stylesheet" href="/css/style.css">
  
  
  
  
</head>


<body class="main-center theme-black" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="https://github.com/shanlanCoding" target="_blank">
          <img class="img-circle img-rotate" src="/images/ha-002-small.png" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">山岚</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md">半吊子全栈开发者</h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> Work in 0755; Home is in 0713</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav menu-highlight">
        
        
        <li class="menu-item menu-item-home">
          <a href="/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">归档</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">分类</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">标签</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-links">
          <a href="/links/">
            
            <i class="icon icon-friendship"></i>
            
            <span class="menu-title">友链</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/shanlanCoding" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=CWRgen1se2phZnxJeHgnamZk" target="_blank" title="Email" data-toggle=tooltip data-placement=top><i class="icon icon-email"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>欢迎交流与分享经验，知无不言言无不尽!</p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">分类</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Java/">Java</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/JavaScript/">JavaScript</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/windows/">windows</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/前端/">前端</a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/博客优化/">博客优化</a><span class="category-list-count">7</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/变得更好/">变得更好</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/心情/">心情</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/手机/">手机</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/服务器/">服务器</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/求职/">求职</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/骚操作/">骚操作</a><span class="category-list-count">3</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签</h3>
    <div class="widget-body">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/AutoJs/">AutoJs</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Git/">Git</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Hexo/">Hexo</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Java/">Java</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JavaScript/">JavaScript</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Java面试题/">Java面试题</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/React/">React</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/React教程/">React教程</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/centOS/">centOS</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java基础/">java基础</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java集合框架/">java集合框架</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nginx/">nginx</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vue/">vue</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/windows-10/">windows 10</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/人脸识别/">人脸识别</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/博客优化/">博客优化</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/吐槽/">吐槽</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/小米6/">小米6</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/思维改变/">思维改变</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/自定义手机号/">自定义手机号</a><span class="tag-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签云</h3>
    <div class="widget-body tagcloud">
      <a href="/tags/AutoJs/" style="font-size: 13.2px;">AutoJs</a> <a href="/tags/Git/" style="font-size: 13.4px;">Git</a> <a href="/tags/Hexo/" style="font-size: 13.8px;">Hexo</a> <a href="/tags/Java/" style="font-size: 13px;">Java</a> <a href="/tags/JavaScript/" style="font-size: 13.2px;">JavaScript</a> <a href="/tags/Java面试题/" style="font-size: 13.6px;">Java面试题</a> <a href="/tags/React/" style="font-size: 14px;">React</a> <a href="/tags/React教程/" style="font-size: 13px;">React教程</a> <a href="/tags/centOS/" style="font-size: 13px;">centOS</a> <a href="/tags/java基础/" style="font-size: 13px;">java基础</a> <a href="/tags/java集合框架/" style="font-size: 13px;">java集合框架</a> <a href="/tags/linux/" style="font-size: 13px;">linux</a> <a href="/tags/nginx/" style="font-size: 13.2px;">nginx</a> <a href="/tags/vue/" style="font-size: 13px;">vue</a> <a href="/tags/windows-10/" style="font-size: 13px;">windows 10</a> <a href="/tags/人脸识别/" style="font-size: 13px;">人脸识别</a> <a href="/tags/博客优化/" style="font-size: 13px;">博客优化</a> <a href="/tags/吐槽/" style="font-size: 13px;">吐槽</a> <a href="/tags/小米6/" style="font-size: 13px;">小米6</a> <a href="/tags/思维改变/" style="font-size: 13px;">思维改变</a> <a href="/tags/自定义手机号/" style="font-size: 13px;">自定义手机号</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">归档</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/12/">十二月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/11/">十一月 2019</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/10/">十月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/09/">九月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/08/">八月 2019</a><span class="archive-list-count">11</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/07/">七月 2019</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/06/">六月 2019</a><span class="archive-list-count">9</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/前端/">前端</a>
              </p>
              <p class="item-title">
                <a href="/post/7080982b.html" class="title">AntD的一个警告解决方法：defaultvalue is invalid for getfielddecorator will set value please use option.initialvalue instead</a>
              </p>
              <p class="item-date">
                <time datetime="2019-12-07T08:58:03.000Z" itemprop="datePublished">2019-12-07</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/JavaScript/">JavaScript</a>
              </p>
              <p class="item-title">
                <a href="/post/cbc43a97.html" class="title">海信A5自动阅读打卡签到工具软件脚本</a>
              </p>
              <p class="item-date">
                <time datetime="2019-12-06T09:03:39.000Z" itemprop="datePublished">2019-12-06</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/JavaScript/">JavaScript</a>
              </p>
              <p class="item-title">
                <a href="/post/ae3d322e.html" class="title"> AutoJs获取的Text文本是乱码|Android爬虫反字体屏蔽乱码解决方案 </a>
              </p>
              <p class="item-date">
                <time datetime="2019-11-23T03:50:19.000Z" itemprop="datePublished">2019-11-23</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/服务器/">服务器</a>
              </p>
              <p class="item-title">
                <a href="/post/1a22163b.html" class="title">GitHub克隆clone太慢添加代理加速访问</a>
              </p>
              <p class="item-date">
                <time datetime="2019-11-13T03:51:13.000Z" itemprop="datePublished">2019-11-13</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/心情/">心情</a>
              </p>
              <p class="item-title">
                <a href="/post/d90e4430.html" class="title">奇葩公司每周晚上占用下班时间开会、团建（跑步）</a>
              </p>
              <p class="item-date">
                <time datetime="2019-11-11T06:36:16.000Z" itemprop="datePublished">2019-11-11</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    <nav id="toc" class="article-toc">
      <h3 class="toc-title">文章目录</h3>
      <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#部署到服务器"><span class="toc-number">1.</span> <span class="toc-text">部署到服务器</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#配置nginx"><span class="toc-number">2.</span> <span class="toc-text">配置nginx</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#第一种方法（不推荐）"><span class="toc-number">2.0.1.</span> <span class="toc-text">第一种方法（不推荐）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#第二种方法"><span class="toc-number">2.0.2.</span> <span class="toc-text">第二种方法</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#找回MySQL密码"><span class="toc-number">3.</span> <span class="toc-text">找回MySQL密码</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#CentOS7开启MySQL远程访问"><span class="toc-number">4.</span> <span class="toc-text">CentOS7开启MySQL远程访问</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#总结："><span class="toc-number">5.</span> <span class="toc-text">总结：</span></a></li></ol>
    </nav>
  </div>
</aside>

<main class="main" role="main">
  <div class="content">
  <article id="post-spring-boot部署到服务器以及安装Redis" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header" name="标题头部>
      
        
  
    <h1 class="article-title" itemprop="name">
      spring-boot部署到CentOS服务器、安装Redis、配置Nginx、MySQL
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/post/c621cb41.html" class="article-date">
	  <time datetime="2019-07-01T16:39:26.000Z" itemprop="datePublished">2019-07-02</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/categories/服务器/">服务器</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link" href="/tags/nginx/">nginx</a>
  </span>


        
	<span class="article-read hidden-xs">
	    <i class="icon icon-eye-fill" aria-hidden="true"></i>
	    <span id="busuanzi_container_page_pv">
			<span id="busuanzi_value_page_pv">0</span>
		</span>
	</span>


	<span class="article-read hidden-xs">
    	<i class="icon icon-eye-fill" aria-hidden="true"></i>
    	<span id="/post/c621cb41.html" class="leancloud_visitors"  data-flag-title="spring-boot部署到CentOS服务器、安装Redis、配置Nginx、MySQL">
			<span class="leancloud-visitors-count">0</span>
		</span>
    </span>

        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/post/c621cb41.html#comments" class="article-comment-link">评论</a></span>
        
      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody" name="正文">
      
        <h1 id="部署到服务器"><a href="#部署到服务器" class="headerlink" title="部署到服务器"></a>部署到服务器</h1><ol>
<li><p>使用idea的Maven工具，<code>package</code>命令，即可对项目进行打包。也可以手动输入maven命令打包<code>mvn clear package</code></p>
</li>
<li><p>打包完成以后，是一个jar文件，会存放在你项目的target目录下。我通过WinSCP软件上传到我的阿里云服务里。</p>
</li>
<li><p>项目需要用到Redis，所以我还把Redis压缩包上传到了服务器内，参考了该教程进行安装。<a href="https://www.cnblogs.com/zuidongfeng/p/8032505.html" target="_blank" rel="noopener">Centos7下安装redis - 醉东风</a></p>
</li>
<li><p>在设置Redis开机自动启动过程中，使用命令启动和停止Redis命令时，碰到了报错：env: /etc/init.d/redisd: Permission denied</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@github init.d]# service redisd start</span><br><span class="line">env: /etc/init.d/redisd: Permission denied</span><br></pre></td></tr></table></figure>

<p><strong>最后解决方法是：</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">chmod a+x /etc/init.d/redis</span><br><span class="line"></span><br><span class="line">a+x 是给所有人加上可执行权限，包括所有者，所属组，和其他人</span><br><span class="line">o+x 只是给其他人加上可执行权限</span><br></pre></td></tr></table></figure>

</li>
</ol>
<h1 id="配置nginx"><a href="#配置nginx" class="headerlink" title="配置nginx"></a>配置nginx</h1><h3 id="第一种方法（不推荐）"><a href="#第一种方法（不推荐）" class="headerlink" title="第一种方法（不推荐）"></a>第一种方法（不推荐）</h3><p>由于已经有了一个tomcat项目，所以第二个项目必须要在nginx里添加配置，否则访问就需要加端口访问了，我的配置如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span> 第二个项目</span><br><span class="line">		location ^~ /apply &#123;</span><br><span class="line"><span class="meta">			#</span>转发给tomcat处理</span><br><span class="line">			proxy_pass http://127.0.0.1:9090/;</span><br><span class="line">			proxy_set_header  Host       $host;</span><br><span class="line">			proxy_set_header  X-Real-IP    $remote_addr;</span><br><span class="line">			proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;</span><br><span class="line">		&#125;		</span><br><span class="line">	&#125;</span><br></pre></td></tr></table></figure>

<p>我的nginx配置文件目录是<code>/etc/nginx/nginx.conf</code>，如果你不知道，可以使用<code>find / -name nginx.conf</code>命令进行全局搜索。</p>
<ol start="5">
<li><p>解决nginx的SpringBoot 静态文件404问题：</p>
<pre><code>单独匹配项目还不够，还需要**匹配项目的静态文件**，否则你的css和js等静态文件加载会出现404的情况，我的匹配规则如下：</code></pre>   <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"> location ~ \.(css|html|htm|js|gif|jpg|jpeg|png|bmp|swf)$  &#123; </span><br><span class="line"> 	proxy_pass http://127.0.0.1:9090; </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>   <strong>最后记得重新加载nginx配置，命令：</strong><code>nginx -s reload</code></p>
</li>
</ol>
<h3 id="第二种方法"><a href="#第二种方法" class="headerlink" title="第二种方法"></a>第二种方法</h3><p>2019-7-2 19:42:50更新：</p>
<p>第一种方法有弊端。因为项目的请求链接基本是固定的。</p>
<p>例如项目的登陆地址是：<a href="http://www.gobyte.cn/login" target="_blank" rel="noopener">www.gobyte.cn/login</a></p>
<p>如果使用了第一种，那么必须加一个目录：<a href="http://www.gobyte.cn/xxx/login。" target="_blank" rel="noopener">www.gobyte.cn/xxx/login。</a></p>
<p>而多了一层目录以后，预先项目的请求地址实际上还是<a href="http://www.xxxx.cn/login。仅仅只是匹配了xxx只能解决页面的加载，实际post的时候会导致404，如果不想404，就只能把所有的请求都转发。那样其他的项目就会发生冲突。或者修改项目的post请求，给请求也加上/xxx/目录，但是这样弊端很大，因为需要改动源代码，所以可以通过第二种方法，使用二级域名来对应新的项目。" target="_blank" rel="noopener">www.xxxx.cn/login。仅仅只是匹配了xxx只能解决页面的加载，实际post的时候会导致404，如果不想404，就只能把所有的请求都转发。那样其他的项目就会发生冲突。或者修改项目的post请求，给请求也加上/xxx/目录，但是这样弊端很大，因为需要改动源代码，所以可以通过第二种方法，使用二级域名来对应新的项目。</a></p>
<ol>
<li><p>添加dns解析，例如我第二个项目打算使用二级域名为：b.gobyte.cn，那么把dns的解析为b，至于记录值还是你的服务器ip</p>
</li>
<li><p>修改nginx.conf配置：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span> 第二个项目</span><br><span class="line">   server &#123;</span><br><span class="line">        listen	80; #你要监控的端口。https是监控443</span><br><span class="line">        server_name b.gobyte.cn; #填写你要项目域名</span><br><span class="line">        index index.html index.htm index.php default.html default.htm default.php;</span><br><span class="line"></span><br><span class="line">        location / &#123;</span><br><span class="line">            proxy_pass http://127.0.0.1:9090;</span><br><span class="line">			proxy_set_header  Host       $host;</span><br><span class="line">			proxy_set_header  X-Real-IP    $remote_addr;</span><br><span class="line">			proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;</span><br><span class="line">        &#125;</span><br><span class="line">        error_page   500 502 503 504  /50x.html;</span><br><span class="line">        location = /50x.html &#123;</span><br><span class="line">            root   html;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<ol start="3">
<li><p><code>nginx -s reload</code> 进行重新加载nginx配置</p>
<p>参考：<a href="https://www.cnblogs.com/banma/p/9069858.html" target="_blank" rel="noopener">nginx在一个服务器上配置两个项目，并通过两个不同的域名访问</a></p>
</li>
</ol>
</li>
</ol>
<h1 id="找回MySQL密码"><a href="#找回MySQL密码" class="headerlink" title="找回MySQL密码"></a>找回MySQL密码</h1><p>我MySQL安装很久了，但是很少使用，所以密码也不记得。</p>
<p>尝试使用MySQL登陆，结果提示被拒绝：<code>ERROR 1045 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: NO)</code></p>
<ol>
<li><p>使用命令停止MySQL服务：<code>systemctl stop mysqld</code></p>
</li>
<li><p>用以下命令启动MySQL，以不检查权限的方式启动：<code>mysqld --skip-grant-tables &amp;</code></p>
</li>
<li><p>登录mysql：<code>mysql -uroot</code>或<code>mysql</code></p>
</li>
<li><p>登陆MySQL后，使用 <code>\s</code>命令查询MySQL版本号</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">mysql&gt;</span> \s</span><br><span class="line">--------------</span><br><span class="line">mysql  Ver 14.14 Distrib 5.7.24, for Linux (x86_64) using  EditLine wrapper</span><br><span class="line"></span><br><span class="line">Connection id:          4</span><br><span class="line">Current database:</span><br><span class="line">Current user:           root@localhost</span><br><span class="line">SSL:                    Not in use</span><br><span class="line">Current pager:          stdout</span><br><span class="line">Using outfile:          ''</span><br><span class="line">Using delimiter:        ;</span><br><span class="line">Server version:         5.7.24 MySQL Community Server (GPL)</span><br><span class="line">Protocol version:       10</span><br><span class="line">Connection:             Localhost via UNIX socket</span><br><span class="line">Server characterset:    latin1</span><br><span class="line">Db     characterset:    latin1</span><br><span class="line">Client characterset:    utf8</span><br><span class="line">Conn.  characterset:    utf8</span><br><span class="line">UNIX socket:            /var/lib/mysql/mysql.sock</span><br><span class="line">Uptime:                 6 min 22 sec</span><br><span class="line"></span><br><span class="line">Threads: 1  Questions: 20  Slow queries: 0  Opens: 110  Flush tables: 1  Open tables: 105  Queries per second avg: 0.052</span><br><span class="line">--------------</span><br><span class="line"></span><br><span class="line"><span class="meta">mysql&gt;</span></span><br></pre></td></tr></table></figure>



</li>
</ol>
<ol start="5">
<li><p>然后更新root密码</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">mysql5.7以下版本：</span><br><span class="line">UPDATE mysql.user SET Password=PASSWORD('root') where USER='root';</span><br><span class="line"></span><br><span class="line">mysql5.7版本：</span><br><span class="line">UPDATE mysql.user SET authentication_string=PASSWORD('root') where USER='root';</span><br></pre></td></tr></table></figure>
</li>
<li><p>刷新权限：<code>flush privileges;</code></p>
</li>
<li><p>退出mysql命令：<code>exit</code>或<code>quit</code></p>
</li>
<li><p>使用root用户重新登录mysql</p>
   <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysql -uroot -proot</span><br></pre></td></tr></table></figure>

<p>   参考自：<a href="https://blog.csdn.net/qq_32786873/article/details/79225039" target="_blank" rel="noopener">解决MySQL登录报ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)的问题 </a></p>
</li>
</ol>
<h1 id="CentOS7开启MySQL远程访问"><a href="#CentOS7开启MySQL远程访问" class="headerlink" title="CentOS7开启MySQL远程访问"></a>CentOS7开启MySQL远程访问</h1><details>
    <summary>点击查看完整的脚本命令</summary>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">[root@github ~]# mysql -uroot -proot #登陆MySQL</span><br><span class="line"><span class="meta">mysql&gt;</span> use mysql #选择MySQL表</span><br><span class="line">Reading table information for completion of table and column names</span><br><span class="line">You can turn off this feature to get a quicker startup with -A</span><br><span class="line">Database changed</span><br><span class="line"><span class="meta">mysql&gt;</span> update user set host='%' where user='root' and host='localhost'; #修改登陆主机</span><br><span class="line">Query OK, 1 row affected (0.00 sec)</span><br><span class="line">Rows matched: 1  Changed: 1  Warnings: 0</span><br><span class="line"><span class="meta">mysql&gt;</span> UPDATE user SET password=password("root") WHERE user='root'; 	#重新设置一下密码，因为这时密码已失效，虽然本地还可以原密码登录，可远程改了host后还是没法访问</span><br><span class="line"><span class="meta">mysql&gt;</span> flush privileges; #刷新权限</span><br><span class="line">Query OK, 0 rows affected (0.00 sec)</span><br><span class="line"><span class="meta">mysql&gt;</span> exit #退出 MySQL</span><br><span class="line">Bye</span><br><span class="line">[root@github ~]# service mysqld restart; #重启MySQL</span><br><span class="line">Redirecting to /bin/systemctl restart  mysqld.service</span><br><span class="line">Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.</span><br></pre></td></tr></table></figure>

</details>
参考：[CentOS7和CentOS6怎样开启MySQL远程访问](https://blog.csdn.net/u014066037/article/details/55194802)

<h1 id="总结："><a href="#总结：" class="headerlink" title="总结："></a>总结：</h1><ol>
<li><p>打包SpringBoot 项目使用：<code>mvn clean package</code></p>
</li>
<li><p>在Linux 启动项目使用命令：<code>nohup java -jar xxx.jar &amp;</code>   ；停止运行使用:<code>ps -ef|grep xxxx.jar</code>查询出pid，然后使用：<code>kill -9 pid</code>命令杀死进程，你还可以使用脚本来管理程序：</p>
<details>
    <summary>点击展开完整的脚本</summary>
       <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span>!/bin/bash</span><br><span class="line"><span class="meta">#</span>这里可替换为你自己的执行程序，其他代码无需更改</span><br><span class="line">APP_NAME=apply-0.0.1-SNAPSHOT.jar</span><br><span class="line"><span class="meta">#</span>使用说明，用来提示输入参数</span><br><span class="line">usage() &#123;</span><br><span class="line">    echo "Usage: sh 执行脚本.sh [start|stop|restart|status]"</span><br><span class="line">    exit 1</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">#</span>检查程序是否在运行</span><br><span class="line">is_exist()&#123;</span><br><span class="line">  pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '&#123;print $2&#125;' `</span><br><span class="line"><span class="meta">  #</span>如果不存在返回1，存在返回0     </span><br><span class="line">  if [ -z "$&#123;pid&#125;" ]; then</span><br><span class="line">   return 1</span><br><span class="line">  else</span><br><span class="line">    return 0</span><br><span class="line">  fi</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">#</span>启动方法</span><br><span class="line">start()&#123;</span><br><span class="line">  is_exist</span><br><span class="line">  if [ $? -eq "0" ]; then</span><br><span class="line">    echo "$&#123;APP_NAME&#125; is already running. pid=$&#123;pid&#125; ."</span><br><span class="line">  else</span><br><span class="line">    nohup java -jar $APP_NAME &gt; /dev/null 2&gt;&amp;1 &amp;</span><br><span class="line">  fi</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">#</span>停止方法</span><br><span class="line">stop()&#123;</span><br><span class="line">  is_exist</span><br><span class="line">  if [ $? -eq "0" ]; then</span><br><span class="line">    kill -9 $pid</span><br><span class="line">  else</span><br><span class="line">    echo "$&#123;APP_NAME&#125; is not running"</span><br><span class="line">  fi  </span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">#</span>输出运行状态</span><br><span class="line">status()&#123;</span><br><span class="line">  is_exist</span><br><span class="line">  if [ $? -eq "0" ]; then</span><br><span class="line">    echo "$&#123;APP_NAME&#125; is running. Pid is $&#123;pid&#125;"</span><br><span class="line">  else</span><br><span class="line">    echo "$&#123;APP_NAME&#125; is NOT running."</span><br><span class="line">  fi</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">#</span>重启</span><br><span class="line">restart()&#123;</span><br><span class="line">  stop</span><br><span class="line">  start</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">#</span>根据输入参数，选择执行对应方法，不输入则执行使用说明</span><br><span class="line">case "$1" in</span><br><span class="line">  "start")</span><br><span class="line">    start</span><br><span class="line">    ;;</span><br><span class="line">  "stop")</span><br><span class="line">    stop</span><br><span class="line">    ;;</span><br><span class="line">  "status")</span><br><span class="line">    status</span><br><span class="line">    ;;</span><br><span class="line">  "restart")</span><br><span class="line">    restart</span><br><span class="line">    ;;</span><br><span class="line">  *)</span><br><span class="line">    usage</span><br><span class="line">    ;;</span><br><span class="line">esac</span><br></pre></td></tr></table></figure>

</details>


</li>
</ol>
<ol start="3">
<li><p>安装和设置Redis参考该教程：<a href="https://www.cnblogs.com/zuidongfeng/p/8032505.html" target="_blank" rel="noopener">Centos7下安装redis - 醉东风</a></p>
</li>
<li><p>多个项目，可以使用反向代理Nginx工具，它的优点是支持80端口访问多个项目；负载均衡（目前我没用上）；反向代理其他服务器（例如反向代理新浪微博做图床）等等</p>
</li>
<li><p><del>MySQL密码也忘了，后面还要更新下找回MySQL密码。</del> 已经在2019-7-2 18:32:12更新。 <a href="#找回MySQL密码">找回MySQL密码</a></p>
</li>
</ol>

      
    </div>

    <div class="article-footer" name="文章脚部">
      <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="https://blog.gobyte.cn/post/c621cb41.html" title="spring-boot部署到CentOS服务器、安装Redis、配置Nginx、MySQL" target="_blank" rel="external">https://blog.gobyte.cn/post/c621cb41.html</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://github.com/shanlanCoding" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/images/ha-002-small.png" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://github.com/shanlanCoding" target="_blank"><span class="text-dark">山岚</span><small class="ml-1x">半吊子全栈开发者</small></a></h3>
        <div>大龄萌新；新时代福娃；喜欢东搞西搞；对待问题有独到的见解；</div>
      </div>
    </figure>
  </div>
</div>


    </div>
  </article>
  
    
  <section id="comments">
  	
      <div id="vcomments"></div>
    
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/post/cfce32d8.html" title="解决新浪/微博图床图片403错误防盗链问题"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
    </li>
    
    
    <li class="next">
      <a href="/post/7294a25e.html" title="入门-利用Java免费使用百度人脸识别对妹纸进行打分"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
    <li class="toggle-toc">
      <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false" title="文章目录" role="button">
        <span>[&nbsp;</span><span>文章目录</span>
        <i class="text-collapsed icon icon-anchor"></i>
        <i class="text-in icon icon-close"></i>
        <span>]</span>
      </a>
    </li>
    
  </ul>
  
  
  
  <div class="bar-right">
    
  </div>
  </div>
</nav>
  



  	<script>
	  <!-- 百度站长自动推送链接 -->
		(function(){
		var bp = document.createElement('script');
		var curProtocol = window.location.protocol.split(':')[0];
		if (curProtocol === 'https') {
			bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
		}
		else {
			bp.src = 'http://push.zhanzhang.baidu.com/push.js';
		}
		var s = document.getElementsByTagName("script")[0];
		s.parentNode.insertBefore(bp, s);
		})();
	</script>
</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/shanlanCoding" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=CWRgen1se2phZnxJeHgnamZk" target="_blank" title="Email" data-toggle=tooltip data-placement=top><i class="icon icon-email"></i></a></li>
        
    </ul>



	<div class="powered-by" name="不蒜子" sytle="font-size:12px">
		<i class="icon icon-users"></i>
		<span id="busuanzi_container_site_uv">
			总访客 : <span id="busuanzi_value_site_uv"></span>
		</span><br/>
		<i class="icon icon-eye-fill"></i>
		<span id="busuanzi_container_site_pv">
		    总阅读 : <span id="busuanzi_value_site_pv"></span>
		</span>
	</div>
    
	<div class="copyright" name="作者">
		
		<div class="publishby">
			Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
		</div>
	</div>

</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>

<script>
	window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')

		<!-- 百度统计 -script.ejs --> 
		var _hmt = _hmt || [];
		(function() {
		  var hm = document.createElement("script");
		  hm.src = "https://hm.baidu.com/hm.js?e003775b21b75a71e1396c1fc395cce7";
		  var s = document.getElementsByTagName("script")[0]; 
		  s.parentNode.insertBefore(hm, s);
		})();

		<!-- 新浪云防盗链 -->
		var link = "" ;
		setTimeout( function(){
			$("img").each( (i,o) => {
				var o = $(o);
				if(o.attr("src").indexOf("sinaimg") > 0 ){
					o.attr("referrerpolicy","no-referrer");
					link = o.attr("src");
					o.attr("src",link);
				}
			});
		},1000);

</script>

<script src="/js/plugin.min.js"></script>
<script src="/js/application.js"></script>

    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/js/insight.js"></script>






	
   
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




   
    
  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/valine"></script>
  <script type="text/javascript">
  var GUEST = ['nick', 'mail', 'link'];
  var meta = 'nick,mail,link';
  meta = meta.split(',').filter(function(item) {
    return GUEST.indexOf(item) > -1;
  });
  new Valine({
    el: '#vcomments',
    verify: false,
    notify: false,
    appId: 'ksrz2lYRLkGCOqMraVC2gBB3-gzGzoHsz',
    appKey: 'ehlbHl0wgN6gbvN4NQexYxnl',
    placeholder: '说点什么吧？',
    avatar: 'robohash',
    meta: meta,
    pageSize: '10' || 10,
    visitor: true
  });
  </script>

     







</body>
</html>